//
//  NBStatusToolBar.swift
//  NBSinaWeibo
//
//  Created by ac on 16/5/25.
//  Copyright © 2016年 ac. All rights reserved.
//

import UIKit
import SnapKit

private let separateWidth = 1 / UIScreen.mainScreen().scale

class NBStatusToolBar: UIView {

    private lazy var repostBtn = UIButton()
    private lazy var commentBtn = UIButton()
    private lazy var favourBtn = UIButton()
    private lazy var leftSeparateView = UIView()
    private lazy var rightSeparateView = UIView()
    
    //添加视图模型属性
    var statusViewModel: NBStatusViewModel? {
        didSet {
            repostBtn.setTitle(statusViewModel?.repostsText, forState: .Normal)
            commentBtn.setTitle(statusViewModel?.commentsText, forState: .Normal)
            favourBtn.setTitle(statusViewModel?.attitudesText, forState: .Normal)
        }
    }

    
    override init(frame: CGRect) {
        super.init(frame: frame)
//        self.backgroundColor = UIColor.yellowColor()
        setupUI()
    }
    
    private func setupUI(){
        addBtn(repostBtn, title: "转发", imageName: "timeline_icon_retweet")
        addBtn(commentBtn, title: "评论", imageName: "timeline_icon_comment")
        addBtn(favourBtn, title: "赞", imageName: "timeline_icon_like")
        addSubview(leftSeparateView)
        addSubview(rightSeparateView)
        
        repostBtn.snp_makeConstraints { (make) in
            make.top.equalTo(self)
            make.left.bottom.equalTo(self)
        }
        
        leftSeparateView.snp_makeConstraints { (make) in
            make.left.equalTo(repostBtn.snp_right)
            make.centerY.equalTo(self)
            make.height.equalTo(self).multipliedBy(0.5)
            make.width.equalTo(separateWidth)
        }
        
        commentBtn.snp_makeConstraints { (make) in
            make.left.equalTo(repostBtn.snp_right)
            make.width.top.bottom.equalTo(repostBtn)
        }
        
        rightSeparateView.snp_makeConstraints { (make) in
            make.left.equalTo(commentBtn.snp_right)
            make.centerY.equalTo(self)
            make.height.equalTo(self).multipliedBy(0.5)
            make.width.equalTo(separateWidth)
        }
        favourBtn.snp_makeConstraints { (make) in
            make.left.equalTo(commentBtn.snp_right)
            make.width.top.bottom.equalTo(repostBtn)
            make.right.equalTo(self)
        }
        
        leftSeparateView.backgroundColor = UIColor.lightGrayColor()
        rightSeparateView.backgroundColor = UIColor.lightGrayColor()
        

        
    }
    
    private func addBtn(btn: UIButton,title: String, imageName: String){
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(10)
        btn.titleLabel?.textAlignment = .Center
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        btn.sizeToFit()
        addSubview(btn)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
